procedure TcsInfoDefine.sigInit(mth,Url:string;var idHttp1:TIdHttp;para:string='');stdcall;
var
temp,headStr,curTimeStamp,wSigStr,curTime,myContType :string;
headjo: ISuperobject;
myD:TDateTime;
i : Integer;
begin
myD := now;
idHttp1.Request.Clear;
myContType := 'application/json';
idHttp1.Request.ContentType := myContType;
idHttp1.Request.CustomHeaders.AddValue('x-ca-signature-headers','x-ca-key,x-ca-timestamp');
idHttp1.Request.CustomHeaders.AddValue('x-ca-key',Fapp_id);
idHttp1.Request.Accept := '*/*';
curTimeStamp := trim(IntToStr(GetJavaTime(myD)));
idHttp1.Request.CustomHeaders.AddValue('x-ca-timestamp',curTimeStamp);
curTime := FormatDateTime('yyyy-mm-dd hh:nn:ss',myD);
idHttp1.Request.CustomHeaders.AddValue('Date',curTime);
headStr := '{"x-ca-key":"' Fapp_id '","x-ca-timestamp":' curTimeStamp '}';
headJo := SO(headStr);
wSigStr := mth #10 '*/*' #10 myContType #10 curTime #10;
for i := 0 to headJo.AsObject.count-1 do
wSigStr := wSigStr lowercase(HeadJo.AsObject.GetNames.AsArray[i].AsString ':'
trim(headJo.AsObject.GetValues.AsArray[i].AsString)) #10;
wSigStr := wSigStr Url;
if trim(para) <> '' then wSigStr := wSigStr '?' para;
temp := genSigInfo(wSigStr,Fapp_key);
idHttp1.Request.CustomHeaders.AddValue('x-ca-signature',temp);
end;
function TcsInfoDefine.genSigInfo(const sigStr,sigKey:string):pChar;stdcall;
var
temp :string;
begin
temp := THMACUtils<TIdHMACSHA256>.HMAC_Base64(UTF8Encode(sigKey),UTF8Encode(sigStr));
result := pChar(temp);
end;
评论